/*
 * ListAttributePanel.java
 *
 * Created on 9. Juni 2008, 23:13
 */

package twi.view;

import java.util.ArrayList;

import jtools.gui.CodeCompletionTextArea;
import twi.KeySearch;
import twi.sparql.grammer.SparqlList;
import twi_project.TWI;

/**
 * 
 * @author Soeren
 */
public class ListAttributePanel extends javax.swing.JPanel {

	private ArrayList<SparqlList> sparqlLists;
	private ArrayList<String> domainList;

	/**
	 * Creates new form ListAttributePanel
	 * 
	 * @param arrayList2
	 * @param arrayList
	 * @param varName
	 */
	public ListAttributePanel(String varName, ArrayList<SparqlList> arrayList,
			ArrayList<String> domains) {
		initComponents();
		this.jTextField1.setText(varName);
		this.sparqlLists = arrayList;
		this.domainList = domains;
		if (domains != null) {
			((CodeCompletionTextArea) this.jTextArea1).setWordList(KeySearch
					.getVocabulary(TWI.getInstance().getOntologieModel(),
							domains));
			for (int i = 0; i < domains.size(); i++)
				this.list1.addItem(domains.get(i));
		} else
			((CodeCompletionTextArea) this.jTextArea1).setWordList(KeySearch
					.getCompleteVocabulary(TWI.getInstance()
							.getOntologieModel()));

	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated
	// Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		list1 = new java.awt.List();
		jTextField1 = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		jTextArea1 = new CodeCompletionTextArea();
		jButton1 = new javax.swing.JButton();
		list2 = new java.awt.List();
		jButton2 = new javax.swing.JButton();

		jLabel1.setText("Variable Name");
		jLabel1.setName("jLabel1"); // NOI18N

		jLabel2.setText("Domain");
		jLabel2.setName("jLabel2"); // NOI18N

		list1.setName("list1"); // NOI18N

		jTextField1.setEditable(false);
		jTextField1.setName("jTextField1"); // NOI18N

		jLabel3.setText("Values");
		jLabel3.setName("jLabel3"); // NOI18N

		jScrollPane1.setName("jScrollPane1"); // NOI18N

		jTextArea1.setColumns(20);
		jTextArea1.setRows(1);
		jTextArea1.setName("jTextArea1"); // NOI18N
		jScrollPane1.setViewportView(jTextArea1);

		jButton1.setText("add");
		jButton1.setName("jButton1"); // NOI18N
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		list2.setName("list2"); // NOI18N

		jButton2.setText("del");
		jButton2.setName("jButton2"); // NOI18N

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addComponent(jLabel1)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jTextField1,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												219, Short.MAX_VALUE))
						.addGroup(
								layout
										.createSequentialGroup()
										.addComponent(jLabel2)
										.addGap(37, 37, 37)
										.addComponent(
												list1,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												219, Short.MAX_VALUE))
						.addGroup(
								layout
										.createSequentialGroup()
										.addComponent(jLabel3)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												114, Short.MAX_VALUE)
										.addComponent(
												jScrollPane1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE))
						.addComponent(list2,
								javax.swing.GroupLayout.DEFAULT_SIZE, 291,
								Short.MAX_VALUE)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								layout
										.createSequentialGroup()
										.addGap(89, 89, 89)
										.addComponent(jButton2)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(jButton1)));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel1)
														.addComponent(
																jTextField1,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel2)
														.addComponent(
																list1,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																57,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																jScrollPane1,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel3))
										.addGap(12, 12, 12)
										.addComponent(
												list2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jButton1)
														.addComponent(jButton2))));
	}// </editor-fold>//GEN-END:initComponents

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
		if (list1.getItemCount() > 0) {
			if (!KeySearch.isValid(this.jTextArea1.getText(), this.domainList))
				return;
			this.list2.addItem(this.jTextArea1.getText());
			this.jTextArea1.setText("");
		} else {
			this.list2.addItem(this.jTextArea1.getText());
			this.jTextArea1.setText("");
		}
	}// GEN-LAST:event_jButton1ActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTextArea jTextArea1;
	private javax.swing.JTextField jTextField1;
	private java.awt.List list1;
	private java.awt.List list2;
	// End of variables declaration//GEN-END:variables

}
